package interchange.data;

import interchange.domain.Pago;
import interchange.domain.Transferencia;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

public class JDBCTransferenciaDAO {

	public void delete(Connection conn, String IDTransferencia){
		 String sql = "DELETE FROM Transferencia WHERE (OIDTransferencia = ?) ";
	        PreparedStatement stmt = null;

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1,IDTransferencia);
	            stmt.executeUpdate();
	        } catch (SQLException e) {
	            System.err.println("Message: " + e.getMessage());
	            System.err.println("SQLState: " + e.getSQLState());
	            System.err.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (stmt != null)
	                    stmt.close();
	            } catch (SQLException e) {
	            }
	        }

   
	}

    public void insert(Connection conn, String IDTransferencia, Transferencia t){
    	String sql = "INSERT INTO Transferencia ( OIDTransferencia,NumTarjeta,CVC,FechaCaducidad) VALUES (?, ?,?, ?) ";
        PreparedStatement stmt = null;

        try {
            stmt = conn.prepareStatement(sql);

            stmt.setString(1, IDTransferencia);
            stmt.setInt(2, t.getNumTarjeta());
            stmt.setInt(3,t.getCVC());
            stmt.setDate(4,(java.sql.Date) t.getFechaCaducidad());
            
           

            stmt.executeUpdate();

        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
        }

 	}
    
}



